package com.mfp.java.testYou.ui.mvc;

import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mfp.java.testYou.core.AppContext;
import com.mfp.java.testYou.core.servlets.ManageTestServlet;
import com.mfp.java.testYou.db.model.Test;
import com.mfp.java.testYou.model.UiSelectPair;

public class TestsPage extends AbstractMVC {

	public static final String URL = "/testYou/pages/tests.jsp";
	
	private static final Integer LIST_SIZE = 10;

	public TestsPage(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
		prepareList();
	}

	private void prepareList() {
		List<Test> list = AppContext.getDAO().getAllTests();
		List<UiSelectPair> uiList = new LinkedList<UiSelectPair>();
		for (Test t : list) {
			uiList.add(new UiSelectPair(t.getTitle(), t.getId()));
		}

		getRequest().setAttribute(SelectListComponent.ATTR_LIST_DATA, uiList);
		getRequest().setAttribute(SelectListComponent.ATTR_LIST_NAME, ManageTestServlet.INPUT_TESTID);
		getRequest().setAttribute(SelectListComponent.ATTR_LIST_SIZE, LIST_SIZE);
	}

}
